/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rhserver;

import Entities.ReservationLogs;
import Entities.Resource;
import Entities.User;
import constants.Consts;
import java.util.Date;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

/**
 *
 * @author Bari
 */
public class MyLogger {
    

    public synchronized static void logResourceStart(Resource resource,User user, Date startTime, Date endtime,EntityManager em)
    {
          EntityTransaction tx = em.getTransaction();
          tx.begin();
          ReservationLogs log=new ReservationLogs();
          log.setReservationtime(startTime);
          log.setUid(user);
          log.setRid(resource);
          log.setReservationend(endtime);
          log.setEvent(Consts.LOG_START);
          em.persist(log);
          tx.commit();        
    }
    public synchronized static void logResourceStop(Resource resource,Date stopDate,EntityManager em)
    {
          EntityTransaction tx = em.getTransaction();
          tx.begin();
          ReservationLogs log=new ReservationLogs();
          log.setRid(resource);
          log.setEvent(Consts.LOG_STOP);
          log.setReservationend(stopDate);
          em.persist(log);
          tx.commit();
    }
    public synchronized static void logResourceForceRestart(Resource resource,User user,Date restartTime,EntityManager em)
    {
          EntityTransaction tx = em.getTransaction();
          tx.begin();
          ReservationLogs log=new ReservationLogs();
          log.setReservationtime(restartTime);
          log.setUid(user);
          log.setRid(resource);
          log.setEvent(Consts.LOG_START);
          em.persist(log);
          tx.commit();
    }
    
}
